package com.jvm123.api.api.controller

import com.jvm123.api.util.HexUtil
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

import java.security.MessageDigest

/**
 *
 * @author yawn
 *     2019/10/4 13:55
 *
 */
@RestController
@RequestMapping("digest")
class MessageDigestController {

    /**
     *
     * @param type md5/sha1
     * @param s
     * @return
     */
    @PostMapping("{type}")
    String digest(@PathVariable("type") String type, String s) {
        MessageDigest digest = MessageDigest.getInstance(type.toUpperCase())
        // digest编码
        byte[] result = digest.digest(s.getBytes("utf-8"))
        HexUtil.toHexString(result)
    }
}
